
// CCheckFlags.cpp
//

#include "StdAfx.h"
#include "CheckFlags.h"

void CheckFlags::setFlagOn(unsigned short idx){
    if( arrSize_ <= idx ) 
		return;

    arrFlags_[idx]=1;
}

void CheckFlags::setFlagOn(){
    arrFlags_[nullIdx_]=1;
    nullIdx_++;
}

void CheckFlags::setFlagOff(unsigned short idx){
    if( arrSize_ <= idx ) 
		return;

    arrFlags_[idx]=0;
}

unsigned short CheckFlags::setFlagOntoOff(){
    IS_NULL_RETURN(arrSize_, 0);
    
    for( unsigned short w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 1 ){
            arrFlags_[w] = 0;
            return w;
        }
    }

    return 0;
}

unsigned short CheckFlags::setFlagOfftoOn(){
    IS_NULL_RETURN(arrSize_, 0);

    for( unsigned short w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 0 ){
            arrFlags_[w] = 1;
            return w;
        }
    }

    return 0;
}

unsigned short CheckFlags::getFlagOnCnt(){
    IS_NULL_RETURN(arrSize_, 0);

    unsigned short retValue=0;

    for( unsigned short w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 1 ) 
			retValue++;
    }

    return retValue;
}

unsigned short CheckFlags::getFlagOffCnt(){
    IS_NULL_RETURN(arrSize_, 0);	

    unsigned short retValue=0;

    for( unsigned short w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 0 ) 
			retValue++;
    }

    return retValue;
}

bool CheckFlags::isFullOn(){
    IS_NULL_RETURN(arrSize_, false);

    for( unsigned short w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 0 ) 
			return false;
    }

    return true;
}

bool CheckFlags::isFullOff(){	
    IS_NULL_RETURN(arrSize_, false);

    for( unsigned short w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 1 ) 
			return false;
    }

    return true;
}

bool CheckFlags::isOn(unsigned short idx){
	IS_NULL_RETURN(arrSize_, false);

	if( arrSize_ <= idx )
		return false;

	if( arrFlags_[idx] )
		return true;

	return false;
}

bool CheckFlags::isOff(unsigned short idx){
	IS_NULL_RETURN(arrSize_, false);
	if( arrSize_ <= idx )
		return false;

	if( arrFlags_[idx] == 0 )
		return true;

	return false;
}

void CheckFlags::setFullOn(){ 
    memset(arrFlags_, 1, arrSize_); 
}

void CheckFlags::setFullOff(){ 
    memset(arrFlags_, 0, arrSize_); 
}

unsigned short CheckFlags::getFstOn(){
    IS_NULL_RETURN(arrSize_, false);

    unsigned short w;

    for( w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 1 ) 
			return w;
    }

    return w;
}

unsigned short CheckFlags::getFstOff(){
    IS_NULL_RETURN(arrSize_, false);

    unsigned short w;
    for( w=0 ; w < arrSize_ ; w++ ){
        if( arrFlags_[w] == 0 ) return w;
    }

    return w;
}

unsigned short CheckFlags::getSize(){ 
    return arrSize_; 
}	
